<template>
	<view class="current-activity">
		<view class="current-activity-header">
			<view class="activity-tag activity-tag-groupon">拼团</view>
			<text class="current-activity-title">{{ activityName }}</text>
		</view>
		
		<view class="activity-detail">
			<view class="groupon-info">
				<text class="groupon-count">已有{{ grouponCount }}人成功拼团</text>
				<view class="groupon-avatars">
					<image v-for="(avatar, idx) in grouponAvatars" :key="idx" :src="avatar" mode="aspectFill" class="groupon-avatar"></image>
				</view>
			</view>
			<view class="activity-countdown">
				<text class="countdown-label">距结束</text>
				<text class="countdown-time">{{ countdownTime }}</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref, computed, onMounted, onUnmounted } from 'vue';
	
	const props = defineProps({
		activityType: {
			type: String,
			default: 'groupon'
		},
		currentActivity: {
			type: Object,
			default: () => null
		}
	});
	
	// 拼团活动名称
	const activityName = computed(() => {
		if (props.currentActivity && props.currentActivity.name) {
			return props.currentActivity.name;
		}
		return '3人成团，立减30元';
	});
	
	// 拼团人数
	const grouponCount = ref(128);
	
	// 拼团头像列表
	const grouponAvatars = ref([
		'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1780&q=80',
		'https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2787&q=80',
		'https://images.unsplash.com/photo-1599566150163-29194dcaad36?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2787&q=80'
	]);
	
	// 倒计时
	const countdownTime = ref('23:59:59');
	let timer = null;
	
	// 模拟倒计时
	const startCountdown = () => {
		// 实际项目中应该根据活动结束时间计算倒计时
		// 这里仅作为示例
		let hours = 23;
		let minutes = 59;
		let seconds = 59;
		
		timer = setInterval(() => {
			seconds--;
			if (seconds < 0) {
				seconds = 59;
				minutes--;
				if (minutes < 0) {
					minutes = 59;
					hours--;
					if (hours < 0) {
						clearInterval(timer);
						return;
					}
				}
			}
			countdownTime.value = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
		}, 1000);
	};
	
	onMounted(() => {
		startCountdown();
	});
	
	onUnmounted(() => {
		if (timer) {
			clearInterval(timer);
		}
	});
</script>

<style lang="scss" scoped>
.current-activity {
	margin-bottom: 15px;
	padding-bottom: 15px;
	border-bottom: 1px dashed #eee;

	.current-activity-header {
		display: flex;
		align-items: center;
		margin-bottom: 10px;

		.activity-tag {
			padding: 2px 6px;
			border-radius: 3px;
			font-size: 11px;
			color: white;
			margin-right: 8px;
			
			&.activity-tag-groupon {
				background-color: #ff6a6a;
			}
		}

		.current-activity-title {
			font-size: 14px;
			font-weight: bold;
			color: #333;
		}
	}

	.activity-detail {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 10px;

		.activity-countdown {
			display: flex;
			align-items: center;

			.countdown-label {
				font-size: 12px;
				color: #666;
				margin-right: 5px;
			}

			.countdown-time {
				font-size: 14px;
				color: #ff3b30;
				font-weight: bold;
			}
		}
	}

	.groupon-info {
		.groupon-count {
			font-size: 13px;
			color: #333;
			margin-bottom: 5px;
		}

		.groupon-avatars {
			display: flex;
			margin-top: 5px;

			.groupon-avatar {
				width: 24px;
				height: 24px;
				border-radius: 50%;
				margin-right: -8px;
				border: 1px solid #fff;
			}
		}
	}
}
</style>